const zlib = require('zlib');
const fs = require('fs');
const json_data = {
    // 你的JSON对象
};

// 将JSON对象转换为字符串
const jsonString = JSON.stringify(json_data);

// 计算原始数据的大小
const originalSize = Buffer.byteLength(jsonString);

// 使用gzip压缩JSON字符串
zlib.gzip(jsonString, (error, compressedData) => {
    if (error) {
        console.error('Compression error:', error);
        return;
    }

    // 计算压缩后的数据大小
    const compressedSize = compressedData.length;

    // 计算压缩比率
    const compressionRatio = (compressedSize / originalSize * 100).toFixed(2);

    console.log(`Original size: ${originalSize} bytes`);
    console.log(`Compressed size: ${compressedSize} bytes`);
    console.log(`Compression ratio: ${compressionRatio}%`);
});